.class public Lcom/qiniu/resumableio/ResumableClient;
.super Lcom/qiniu/auth/Client;
.source "ResumableClient.java"


# instance fields
.field BLOCK_SIZE:I

.field CHUNK_SIZE:I

.field mUpToken:Ljava/lang/String;


# direct methods
.method public constructor <init>(Lorg/apache/http/client/HttpClient;Ljava/lang/String;)V
    .registers 4
    .param p1, "client"    # Lorg/apache/http/client/HttpClient;
    .param p2, "uptoken"    # Ljava/lang/String;

    .prologue
    .line 25
    invoke-direct {p0, p1}, Lcom/qiniu/auth/Client;-><init>(Lorg/apache/http/client/HttpClient;)V

    .line 22
    const/high16 v0, 0x40000

    iput v0, p0, Lcom/qiniu/resumableio/ResumableClient;->CHUNK_SIZE:I

    .line 23
    const/high16 v0, 0x400000

    iput v0, p0, Lcom/qiniu/resumableio/ResumableClient;->BLOCK_SIZE:I

    .line 26
    iput-object p2, p0, Lcom/qiniu/resumableio/ResumableClient;->mUpToken:Ljava/lang/String;

    .line 27
    return-void
.end method


# virtual methods
.method public bput(Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Ljava/lang/String;JJILcom/qiniu/auth/CallRet;)Lcom/qiniu/utils/ICancel;
    .registers 14
    .param p1, "host"    # Ljava/lang/String;
    .param p2, "input"    # Lcom/qiniu/utils/InputStreamAt;
    .param p3, "ctx"    # Ljava/lang/String;
    .param p4, "blockOffset"    # J
    .param p6, "offset"    # J
    .param p8, "writeLength"    # I
    .param p9, "ret"    # Lcom/qiniu/auth/CallRet;

    .prologue
    .line 100
    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    const-string v3, "/bput/"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    const-string v3, "/"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p6, p7}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 101
    .local v1, "url":Ljava/lang/String;
    invoke-virtual {p0}, Lcom/qiniu/resumableio/ResumableClient;->makeClientExecutor()Lcom/qiniu/auth/Client$ClientExecutor;

    move-result-object v0

    .line 102
    .local v0, "client":Lcom/qiniu/auth/Client$ClientExecutor;
    add-long v2, p4, p6

    invoke-virtual {p2, v2, v3, p8, v0}, Lcom/qiniu/utils/InputStreamAt;->toHttpEntity(JILcom/qiniu/auth/Client$ClientExecutor;)Lorg/apache/http/HttpEntity;

    move-result-object v2

    invoke-virtual {p0, v0, v1, v2, p9}, Lcom/qiniu/resumableio/ResumableClient;->call(Lcom/qiniu/auth/Client$ClientExecutor;Ljava/lang/String;Lorg/apache/http/HttpEntity;Lcom/qiniu/auth/CallRet;)Lcom/qiniu/auth/Client$ClientExecutor;

    .line 103
    return-object v0
.end method

.method public encode(Ljava/lang/String;)Ljava/lang/String;
    .registers 4
    .param p1, "data"    # Ljava/lang/String;

    .prologue
    .line 129
    invoke-virtual {p1}, Ljava/lang/String;->getBytes()[B

    move-result-object v0

    const/16 v1, 0xa

    invoke-static {v0, v1}, Landroid/util/Base64;->encodeToString([BI)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public mkblk(Lcom/qiniu/utils/InputStreamAt;JIILcom/qiniu/auth/CallRet;)Lcom/qiniu/utils/ICancel;
    .registers 11
    .param p1, "input"    # Lcom/qiniu/utils/InputStreamAt;
    .param p2, "offset"    # J
    .param p4, "blockSize"    # I
    .param p5, "writeSize"    # I
    .param p6, "ret"    # Lcom/qiniu/auth/CallRet;

    .prologue
    .line 93
    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "http://up.qiniu.com/mkblk/"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 94
    .local v1, "url":Ljava/lang/String;
    invoke-virtual {p0}, Lcom/qiniu/resumableio/ResumableClient;->makeClientExecutor()Lcom/qiniu/auth/Client$ClientExecutor;

    move-result-object v0

    .line 95
    .local v0, "client":Lcom/qiniu/auth/Client$ClientExecutor;
    invoke-virtual {p1, p2, p3, p5, v0}, Lcom/qiniu/utils/InputStreamAt;->toHttpEntity(JILcom/qiniu/auth/Client$ClientExecutor;)Lorg/apache/http/HttpEntity;

    move-result-object v2

    invoke-virtual {p0, v0, v1, v2, p6}, Lcom/qiniu/resumableio/ResumableClient;->call(Lcom/qiniu/auth/Client$ClientExecutor;Ljava/lang/String;Lorg/apache/http/HttpEntity;Lcom/qiniu/auth/CallRet;)Lcom/qiniu/auth/Client$ClientExecutor;

    .line 96
    return-object v0
.end method

.method public mkfile(Ljava/lang/String;JLjava/lang/String;Ljava/util/Map;Ljava/lang/String;Lcom/qiniu/auth/CallRet;)Lcom/qiniu/utils/ICancel;
    .registers 14
    .param p1, "key"    # Ljava/lang/String;
    .param p2, "fsize"    # J
    .param p4, "mimeType"    # Ljava/lang/String;
    .param p6, "ctxs"    # Ljava/lang/String;
    .param p7, "ret"    # Lcom/qiniu/auth/CallRet;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "J",
            "Ljava/lang/String;",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;",
            "Ljava/lang/String;",
            "Lcom/qiniu/auth/CallRet;",
            ")",
            "Lcom/qiniu/utils/ICancel;"
        }
    .end annotation

    .prologue
    .line 107
    .local p5, "params":Ljava/util/Map;, "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    const-string v4, "http://up.qiniu.com/mkfile/"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3, p2, p3}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 108
    .local v2, "url":Ljava/lang/String;
    if-eqz p4, :cond_36

    invoke-virtual {p4}, Ljava/lang/String;->length()I

    move-result v3

    if-lez v3, :cond_36

    .line 109
    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "/mimeType/"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {p0, p4}, Lcom/qiniu/resumableio/ResumableClient;->encode(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 111
    :cond_36
    if-eqz p1, :cond_59

    invoke-virtual {p1}, Ljava/lang/String;->length()I

    move-result v3

    if-lez v3, :cond_59

    .line 112
    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "/key/"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {p0, p1}, Lcom/qiniu/resumableio/ResumableClient;->encode(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 114
    :cond_59
    if-eqz p5, :cond_a7

    invoke-interface {p5}, Ljava/util/Map;->size()I

    move-result v3

    if-lez v3, :cond_a7

    .line 115
    invoke-interface {p5}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v3

    invoke-interface {v3}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v4

    :goto_69
    invoke-interface {v4}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_a7

    invoke-interface {v4}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    .line 116
    .local v0, "a":Ljava/util/Map$Entry;, "Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v3, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v5, "/"

    invoke-virtual {v3, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Ljava/lang/String;

    invoke-virtual {v5, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v5, "/"

    invoke-virtual {v3, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Ljava/lang/String;

    invoke-virtual {p0, v3}, Lcom/qiniu/resumableio/ResumableClient;->encode(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v5, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 117
    goto :goto_69

    .line 120
    .end local v0    # "a":Ljava/util/Map$Entry;, "Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    :cond_a7
    :try_start_a7
    invoke-virtual {p0}, Lcom/qiniu/resumableio/ResumableClient;->makeClientExecutor()Lcom/qiniu/auth/Client$ClientExecutor;

    move-result-object v3

    new-instance v4, Lorg/apache/http/entity/StringEntity;

    invoke-direct {v4, p6}, Lorg/apache/http/entity/StringEntity;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0, v3, v2, v4, p7}, Lcom/qiniu/resumableio/ResumableClient;->call(Lcom/qiniu/auth/Client$ClientExecutor;Ljava/lang/String;Lorg/apache/http/HttpEntity;Lcom/qiniu/auth/CallRet;)Lcom/qiniu/auth/Client$ClientExecutor;
    :try_end_b3
    .catch Ljava/io/UnsupportedEncodingException; {:try_start_a7 .. :try_end_b3} :catch_b5

    move-result-object v3

    .line 124
    :goto_b4
    return-object v3

    .line 121
    :catch_b5
    move-exception v1

    .line 122
    .local v1, "e":Ljava/io/UnsupportedEncodingException;
    invoke-virtual {v1}, Ljava/io/UnsupportedEncodingException;->printStackTrace()V

    .line 123
    invoke-virtual {p7, v1}, Lcom/qiniu/auth/CallRet;->onFailure(Ljava/lang/Exception;)V

    .line 124
    const/4 v3, 0x0

    goto :goto_b4
.end method

.method public putblock(Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/resumableio/PutExtra;Lcom/qiniu/resumableio/PutRet;JLcom/qiniu/auth/JSONObjectRet;)[Lcom/qiniu/utils/ICancel;
    .registers 19
    .param p1, "input"    # Lcom/qiniu/utils/InputStreamAt;
    .param p2, "extra"    # Lcom/qiniu/resumableio/PutExtra;
    .param p3, "putRet"    # Lcom/qiniu/resumableio/PutRet;
    .param p4, "offset"    # J
    .param p6, "callback"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 38
    invoke-virtual {p1}, Lcom/qiniu/utils/InputStreamAt;->length()J

    move-result-wide v2

    sub-long v2, v2, p4

    iget v0, p0, Lcom/qiniu/resumableio/ResumableClient;->BLOCK_SIZE:I

    int-to-long v6, v0

    invoke-static {v2, v3, v6, v7}, Ljava/lang/Math;->min(JJ)J

    move-result-wide v2

    long-to-int v4, v2

    .line 39
    .local v4, "writeNeed":I
    const/4 v0, 0x1

    new-array v8, v0, [Lcom/qiniu/utils/ICancel;

    const/4 v0, 0x0

    const/4 v2, 0x0

    aput-object v2, v8, v0

    .line 40
    .local v8, "canceler":[Lcom/qiniu/utils/ICancel;
    new-instance v1, Lcom/qiniu/resumableio/ResumableClient$1;

    move-object v2, p0

    move-object v3, p3

    move-object v5, p1

    move-wide/from16 v6, p4

    move-object v9, p2

    move-object/from16 v10, p6

    invoke-direct/range {v1 .. v10}, Lcom/qiniu/resumableio/ResumableClient$1;-><init>(Lcom/qiniu/resumableio/ResumableClient;Lcom/qiniu/resumableio/PutRet;ILcom/qiniu/utils/InputStreamAt;J[Lcom/qiniu/utils/ICancel;Lcom/qiniu/resumableio/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V

    .line 88
    .local v1, "ret":Lcom/qiniu/auth/JSONObjectRet;
    const/4 v0, -0x1

    invoke-virtual {v1, v0}, Lcom/qiniu/auth/JSONObjectRet;->onInit(I)V

    .line 89
    return-object v8
.end method

.method protected roundtrip(Lorg/apache/http/client/methods/HttpRequestBase;)Lorg/apache/http/HttpResponse;
    .registers 5
    .param p1, "httpRequest"    # Lorg/apache/http/client/methods/HttpRequestBase;
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 31
    iget-object v0, p0, Lcom/qiniu/resumableio/ResumableClient;->mUpToken:Ljava/lang/String;

    if-eqz v0, :cond_1e

    .line 32
    const-string v0, "Authorization"

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "UpToken "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    iget-object v2, p0, Lcom/qiniu/resumableio/ResumableClient;->mUpToken:Ljava/lang/String;

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {p1, v0, v1}, Lorg/apache/http/client/methods/HttpRequestBase;->setHeader(Ljava/lang/String;Ljava/lang/String;)V

    .line 34
    :cond_1e
    invoke-super {p0, p1}, Lcom/qiniu/auth/Client;->roundtrip(Lorg/apache/http/client/methods/HttpRequestBase;)Lorg/apache/http/HttpResponse;

    move-result-object v0

    return-object v0
.end method
